package com.cloud.pole.merchant.biz;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.mapper.ShopMerchantUserMapper;
import com.cloud.pole.merchant.model.entity.ShopMerchantUser;

/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-08 16:23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ShopMerchantUserBiz extends BaseBiz<ShopMerchantUserMapper, ShopMerchantUser> {

    @Cache(key="shopMechantUser:userName{1}")
    public ShopMerchantUser selectUserByUsername(String userName){
    	ShopMerchantUser user = new ShopMerchantUser();
        user.setUserName(userName);
        return mapper.selectOne(user);
    }

    @Override
    @CacheClear(keys= {"shopMechantUser:userName{1.userName}", "shopMechantUser{1.userId}", "shopMechantUser:mobile{1.mobileArea}{1.mobile}"})
    public void updateSelectiveById(ShopMerchantUser entity) {
        super.updateSelectiveById(entity);
    }
    
	@Cache(key="shopMechantUser{1}")
    public ShopMerchantUser selectByPrimaryKey(Integer id) {
		 return super.selectById(id);
    }

    @Cache(key="shopMechantUser:mobile{1}{2}")
    public ShopMerchantUser selectByMobile(String mobileArea, String mobile){
    	ShopMerchantUser user = new ShopMerchantUser();
        user.setMobile(mobile);
        user.setMobileArea(mobileArea);
        return mapper.selectOne(user);
    }
    
    @CacheClear(keys= {"shopMechantUser:userName{1.userName}", "shopMechantUser{1.userId}", "shopMechantUser:mobile{1.mobileArea}{1.mobile}"})
    public void insertUseGeneratedKeys(ShopMerchantUser entity) {
        mapper.insertUseGeneratedKeys(entity);
    }
}
